<template>
  <div class="search_history_container">
    <van-cell-group>
      <van-cell title="搜索历史">
        <template #right-icon>
          <van-icon
            name="delete"
            v-if="deleteBtnIsShow"
            class="search=icon"
            @click="deleteHistoryValue"
          />
          <div v-else>
            <span @click="claerAllHistoryValues">全部删除</span>
            &nbsp;&nbsp;
            <span @click="deleteHistoryValue">完成</span>
          </div>
        </template>
      </van-cell>
      <van-cell
        v-for="(item, index) in historyValues"
        :key="index"
        :title="item"
        @click="historyCellClick(item)"
      >
        <template #right-icon>
          <van-icon
            name="cross"
            v-show="!deleteBtnIsShow"
            @click="removeValueByIndex(index)"
          />
        </template>
      </van-cell>
    </van-cell-group>
  </div>
</template>

<script>
export default {
  props: ['historyValues'],
  data () {
    return {
      deleteBtnIsShow: true
    }
  },
  methods: {
    deleteHistoryValue () {
      this.deleteBtnIsShow = !this.deleteBtnIsShow
    },
    // 清除全部
    claerAllHistoryValues () {
      this.deleteBtnIsShow = !this.deleteBtnIsShow
      this.$emit('claerAllHistoryValues')
    },
    // 删除单个值
    removeValueByIndex (index) {
      this.$emit('removeValueByIndex', index)
    },
    // 点击历史记录里面的cell单元格
    historyCellClick (queryQ) {
      this.$emit('historyCellClick', queryQ)
    }
  }
}
</script>

<style lang="less" scoped>
.search_history_container {
  /deep/.van-icon {
    font-size: 35px;
  }
  /deep/.van-icon-cross {
    width: 24px;
    height: 24px;
    font-size: 12px;
    line-height: 24px;
    text-align: center;
    color: #ccc;
    border: 1px solid #ccc;
    border-radius: 50%;
  }
}
</style>
